package com.aiwei.tdjk.service.impl;

import com.aiwei.tdjk.bean.Pager;
import com.aiwei.tdjk.dao.extend.RechargeBillExtendMapper;
import com.aiwei.tdjk.dto.request.GetRechargeBillPagerRequest;
import com.aiwei.tdjk.entity.RechargeBill;
import com.aiwei.tdjk.entity.RechargeBillExample;
import com.aiwei.tdjk.service.RechargeBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RechargeBillServiceImpl implements RechargeBillService{

    @Autowired
    private RechargeBillExtendMapper rechargeBillExtendMapper;

    @Override
    public Pager<RechargeBill> find(GetRechargeBillPagerRequest request) {
        request.webParamConvert();
        List<RechargeBill> userList = rechargeBillExtendMapper.find(request);
        int totalCount = rechargeBillExtendMapper.getTotalCount(request);
        Pager<RechargeBill> pager = new Pager<>();
        pager.setPageNumber(request.getPageNumber());
        pager.setPageSize(request.getPageSize());
        pager.setList(userList);
        pager.setTotalCount(totalCount);
        return pager;
    }

    @Override
    public int save(RechargeBill rechargeBill) {
        return rechargeBillExtendMapper.insertSelective(rechargeBill);
    }


    @Override
    public RechargeBill getBySN(String sn) {
        RechargeBillExample example = new RechargeBillExample();
        example.or().andSnEqualTo(sn);
        List<RechargeBill> rechargeBills = rechargeBillExtendMapper.selectByExample(example);
        if (rechargeBills!=null&&rechargeBills.size()>0){
            return rechargeBills.get(0);
        }
        return null;
    }

    @Override
    public void update(RechargeBill rechargeBill) {
        RechargeBillExample example = new RechargeBillExample();
        example.or().andSnEqualTo(rechargeBill.getSn());
        rechargeBillExtendMapper.updateByExampleSelective(rechargeBill,example);
    }

    @Override
    public void deleteBySn(String sn) {
        RechargeBillExample example = new RechargeBillExample();
        example.or().andSnEqualTo(sn);
        int i = rechargeBillExtendMapper.deleteByExample(example);
    }

}
